package com.zhx.mybatislog.config;

import com.zhx.mybatislog.handler.DataLogHandler;
import com.zhx.mybatislog.interceptor.logs.OptLogStatementInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;


@Configuration
public class MybatisConfiguration  {
    //注册拦截器
    @Autowired
    private DataSource dataSource;
    @Autowired
    DataLogHandler dataLogHandler;
    public OptLogStatementInterceptor mybatisInterceptor(){
        return new OptLogStatementInterceptor(new JdbcTemplate(dataSource),dataLogHandler);
    }
        //用下面的方法拦截器执行了两次
//    @Bean
//    ConfigurationCustomizer mybatisConfigurationCustomizer() {
//        return new ConfigurationCustomizer() {
//            @Override
//            public void customize(org.apache.ibatis.session.Configuration configuration) {
////                configuration.addInterceptor(new CompleteSQLInterceptor());
//                configuration.addInterceptor(new OptLogStatementInterceptor(new JdbcTemplate(dataSource),dataLogHandler));
//            }
//        };
//    }

}

